package queue;

import java.util.Stack;

class MyQueue {
    public Stack<Integer> s1;
    public Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();

    }

    public void push(int x) {
        if (!s1.empty()){
            int size = s1.size();
            for (int i = 0; i < size; i++) {
                s2.push(s1.pop());
            }
            s2.push(x);
            size = s2.size();
            for (int i = 0; i < size; i++) {
                s1.push(s2.pop());
            }

        }else{
            int size = s2.size();
            for (int i = 0; i < size; i++) {
                s1.push(s2.pop());
            }
            s1.push(x);
            size = s1.size();
            for (int i = 0; i < size; i++) {
                s2.push(s1.pop());
            }

        }

    }

    public int pop() {
        if (empty()){
            return -1;
        }
        int val = 0;
        if (!s1.empty()){
            val = s1.pop();
        }else{
            val = s2.pop();
        }
        return val;


    }

    public int peek() {
        if (empty()){
            return -1;
        }
        int val = 0;
        if (!s1.empty()){
            val = s1.peek();
        }else{
            val = s2.peek();
        }
        return val;


    }

    public boolean empty() {
        return s1.empty() && s2.empty();

    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
